<?php

namespace App\Admin\Controllers;

use App\Models\BookSelf;
use App\Models\Floor;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class BookSelfController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BookSelf(), function (Grid $grid) {
            $grid->column('floor_id')->display(function ($d){
                return Floor::find($d)->name;
            });
            $grid->column('name');
            $grid->column('sort');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('name');

            });

            $grid->showQuickEditButton();
            $grid->disableViewButton();
            $grid->disableEditButton();
        });
    }



    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BookSelf(), function (Form $form) {
            $form->display('id');
            $form->text('name')->required();
            $form->select('floor_id')->options(Floor::all()->pluck('name', 'id'))->required();
            $form->number('sort')->default(1);

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
